home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6585 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  58 lines

  1. Path: newsserv.zdv.uni-tuebingen.de!news
  2. From: hans.loeffler@student.uni-tuebingen.de
  3. Newsgroups: comp.lang.c++
  4. Subject: Q: Pointer to member fctn within member fctn
  5. Date: Fri, 09 Feb 1996 20:18:14 GMT
  6. Organization: InterNetNews at ZDV Uni-Tuebingen
  7. Message-ID: <4fgab1$h27@newsserv.zdv.uni-tuebingen.de>
  8. Reply-To: hans.loeffler@student.uni-tuebingen.de
  9. NNTP-Posting-Host: zxmkp12.extern.uni-tuebingen.de
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. I have a problem calling a member function through a pointer within
  13. another member function
  14. Consider:
  15.  
  16. typedef void (*pmfctn)(int); //pointer to member function
  17.  
  18. class X {
  19. void f1(int);
  20. void f2(int);
  21.  
  22. pmfctn pf1, pf2;
  23.  
  24. void f3(pmfctn);
  25. };
  26.  
  27. void X::f1(void) {
  28.     // do something
  29.     ...
  30.     return;
  31. }
  32. ...
  33.  
  34. void X::f3(pmfctn pf) {
  35.  
  36. int a = 5;
  37. // I want to call f1 or f2 now
  38. // problem here:
  39. this->*pf(a);  // **
  40. }
  41.  //  ** this results in a runtime error with Borland C++ V4.5, when
  42. calling f3(pf1) or f3(pf2) 
  43. // I initialize pf1 as:
  44. pf1 = &X::f1;
  45.  
  46. In books I only saw things like
  47.  
  48. X *px;
  49.  
  50. px->*pf1(a);
  51. which call the functions from an object and not within a member
  52. function
  53.  
  54. What is wrong with my solution?
  55.  
  56. Hans
  57.  
  58.